package servlet;

import domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by guo on 2017/10/19.
 */
@WebServlet(name = "CartServlet",urlPatterns = "/cartServlet")
public class CartServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //??????б?
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
HttpSession session=request.getSession();
        if(session==null)
        {
            out.write("????????????");
        }
        else {
            List<User>list= (List<User>) session.getAttribute("cart");
                    if(list==null)
                    {
                        out.write("???????");
                    }
                    else {
                out.write("?????б??????<br/>");
                        for (User user:
                             list) {
                         out.write(user.getPname()+"<a href=\"/cart/deleteServlet?id="+user.getPid()+"\">????????</a><br/>"+"<br/>");
                         request.setAttribute("user",user);
                         request.getRequestDispatcher("/DeleteServlet");
                        }
                    }
               }
             }
        }

